﻿using Management.API.Application.Controller.Management;
using Management.API.Application.Controller.Management.Material;
using Management.Errorcode;
using Management.Models.BOMBasicInformation;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;

namespace Management.API.Controllers
{
    /// <summary>
    /// BOM控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TestController : ControllerBase
    { 
        private readonly ILogger<TestController> _logger;
        private readonly IMediator _mediator;
        public TestController(ILogger<TestController> logger, IMediator mediator)
        {
            _logger = logger;
            _mediator = mediator;
        }

        /// <summary>           
        /// 获取测试数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetTestData()
        {
            return Ok("测试数据");
        }

        /// <summary>
        /// 获取BOM信息
        /// </summary>
        /// <param name="query">获取BOM的请求查询</param>
        /// <returns>BOM信息</returns>
        [HttpGet]
        public async Task<ApiResult> GetBasicInformation([FromQuery] GetBasicInformationCommand query)
        {
            return await _mediator.Send(query);
        }

        /// <summary>
        /// 添加BOM信息
        /// </summary>
        /// <param name="command">添加BOM的请求命令</param>
        /// <returns>操作结果</returns> AddBomCommand
        [HttpPost]
        public async Task<ApiResult> AddBasicInformation([FromBody] AddBasicInformationCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 删除BOM信息
        /// </summary>
        /// <param name="BasicinformationId">要删除的BOM的唯一标识符</param>
        /// <returns>操作结果</returns>
        [HttpPost]
        public async Task<ApiResult> DeleteBasicInformation(int BasicinformationId)
        {
            var command = new DeleteBasicInformationCommand { BasicinformationId = BasicinformationId };
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 根据BOMID获取BOM信息
        /// </summary>
        /// <param name="basicinformationId">BOM的唯一标识符</param>
        /// <returns>BOM信息</returns>
        [HttpGet]
        public async Task<ApiResult> GetBomById(int basicinformationId)
        {
            var query = new GetIDBasicInformationCommand { BasicinformationId = basicinformationId };
            return await _mediator.Send(query);
        }

        /// <summary>
        /// 修改BOM信息
        /// </summary>
        /// <param name="command">修改BOM的请求命令</param>
        /// <returns>操作结果</returns>
        [HttpPost]
        public async Task<ApiResult> UpdateBasicInformation([FromBody] UpdateBasicInformationCommand command)
        {
            return await _mediator.Send(command);
        }






    }
}
